<template>
    <div>
      {{title}} <br>
      <input type="text" v-model="titleForCreate">
      <!--点击这个按钮区新增一个iss-->
      <button @click="add">click</button>
    </div>
</template>

<script>
  import axios from "axios"
  export default {
    name: 'HelloWorld',
    data(){
      return{
        title:"",
        titleForCreate:""
      }
    },
    methods:{
      async add(){
        //方式请求去新增iss
        //9cb410cdb6faf002c35d3e6cfffc767ca323ca25
        await axios({
          method:"post",
          url:"https://api.github.com/repos/betterDamu/sh_200318/issues",
          data: {
            "title": this.titleForCreate
          },
         /* github: token是用来标识权限信息的
                    github的后台接口需要我们将token信息存在请求头的
                    Authorization字段中  而且有固定的格式: token val*/
          headers:{
            "Authorization":"token 9cb410cdb6faf002c35d3e6cfffc767ca323ca25"
          }
        })
      }
    },
    async mounted(){
      //发送ajax请求
      //请求地址:https://api.github.com/repos/betterDamu/sh_200318/issues
      const body = await axios({
        method:"get",
        url:"https://api.github.com/repos/betterDamu/sh_200318/issues"
      })
      this.title = body.data[0].title
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>

</style>
